package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.NameBean;

public class FinalControl extends HttpServlet{
	
	public FinalControl(){
		System.out.println("FinalControl()");
	}
	public void init(){
		System.out.println("FinalControl.init()");
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	  throws IOException, ServletException{
		System.out.println("FinalControl.doGet()");
		RequestDispatcher dispatcher;
		try {
			NameBean nb = (NameBean)request.getAttribute("naam");
			if(nb.validate())
				dispatcher = request.getRequestDispatcher("/bye.jsp");
			else
				dispatcher = request.getRequestDispatcher("/main");
		}
		catch (NullPointerException e)
		{
			dispatcher = request.getRequestDispatcher("/main");
		}
		dispatcher.forward(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	  throws IOException, ServletException{
		System.out.println("FinalControl.doPost()");
	}
	public void destroy(){
		System.out.println("FinalControl.destroy()");
	}
}
